﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using MiniStock.Database;
using MiniStock.Entities.Common;
using MiniStock.Entities.Stock;

namespace MiniStock.BusinessLogic.EventDispatcher
{
    public class EntityQueryLogic
    {
        [Dependency]
        public EntityDbContext Context { get; set; }

        public EntityBase GetEntityByHash(string hash)
        {
            return Context.GetEntityByHash(hash);
        }

        public List<EntityBase> ListEntity(string entity, Dictionary<string, string> filter)
        {
            var entityType =
                SerializationHelper.KnownEntityTypes.FirstOrDefault(i => i.Name == entity);

            List<EntityBase> result = new List<EntityBase>();
            var set = Context.Set(entityType);
            foreach (var e in set)
            {
                result.Add(e as EntityBase);
            }
            return result;
        }
    }
}
